package sfeir.authform.server.taglib;

import java.io.IOException;
import java.io.Writer;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import sfeir.authform.server.authservice.AuthService;
import sfeir.authform.server.authservice.AuthServiceFactory;
import sfeir.authform.server.authservice.AuthServiceStandard;

public class SignupForm extends TagSupport {
    private String emailLabel = "Email";
    private String passwordLabel = "Password";
    private String nicknameLabel = "Name";
    private String confirmpasswordLabel = "Login";
    private String submitLabel = "Subscribe";
    private String returnURL = "/";
    
    /**
     * 
     */
    private static final long serialVersionUID = -3937034608298993606L;

    @Override
    public int doStartTag() throws JspException {
        AuthServiceStandard service = (AuthServiceStandard) AuthServiceFactory.getAuthService(AuthServiceFactory.STANDARD);
        Writer out = pageContext.getOut();
        try {
            out.write("<form action=\"");
            out.write(service.createSignupURL(returnURL));
            out.write("\" method=\"POST\">");
            out.write("<input type=\"hidden\" name=\"return\" value=\"");
            out.write(returnURL);
            out.write("\"/>");
            out.write("<label>");
            out.write(emailLabel);
            out.write("<input type=\"text\" name=\"email\" /></label>");
            out.write("<label>");
            out.write(passwordLabel);
            out.write("<input type=\"password\" name=\"password\" /></label>");
            out.write("<label>");
            out.write(confirmpasswordLabel);
            out.write("<input type=\"password\" name=\"password_bis\" /></label>");
            out.write("<label>");
            out.write(nicknameLabel);
            out.write("<input type=\"text\" name=\"nickname\" /></label>");
        } catch (IOException e) {
            e.printStackTrace();
        }
        return EVAL_BODY_INCLUDE;
    }
    
    @Override
    public int doEndTag() throws JspException {
        Writer out = pageContext.getOut();
        try {
            out.write("<input type=\"submit\" value=\"");
            out.write(submitLabel);
            out.write("\"/>");
            out.write("</form>");
        } catch (IOException e) {
            e.printStackTrace();
        }
        return EVAL_PAGE;
    }

    public String getPasswordLabel() {
        return passwordLabel;
    }

    public void setPasswordLabel(String passwordLabel) {
        this.passwordLabel = passwordLabel;
    }

    public String getSubmitLabel() {
        return submitLabel;
    }

    public void setSubmitLabel(String submitLabel) {
        this.submitLabel = submitLabel;
    }

    public String getReturnURL() {
        return returnURL;
    }

    public void setReturnURL(String returnURL) {
        this.returnURL = returnURL;
    }

    public String getConfirmpasswordLabel() {
        return confirmpasswordLabel;
    }

    public void setConfirmpasswordLabel(String confirmpasswordLabel) {
        this.confirmpasswordLabel = confirmpasswordLabel;
    }

    public String getEmailLabel() {
        return emailLabel;
    }

    public void setEmailLabel(String emailLabel) {
        this.emailLabel = emailLabel;
    }

    public String getNicknameLabel() {
        return nicknameLabel;
    }

    public void setNicknameLabel(String nicknameLabel) {
        this.nicknameLabel = nicknameLabel;
    }
}
